<template>
  <el-dialog v-model="dialogVisible" title="报检" width="900px">
    <el-form class="aceauForm" label-width="120px" :model="state.form">
      <el-row :gutter="12">
        <el-col :span="12">
          <el-form-item label="检验方式">
            <el-select
              v-model="state.form.checkMode"
              class="m-2"
              clearable
              placeholder="选择方式"
              style="width: 300px"
            >
              <el-option
                v-for="item in checkModes"
                :key="item.id"
                :label="item.checkModeName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="报检数量">
            <el-input v-model="state.form.inspectQty" placeholder="" />
          </el-form-item>
        </el-col> -->
      </el-row>
    </el-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="reportInspect">报检</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
  import { productReportInspectApi } from '@/api/qm/reportInspectApi'
  const $baseLoading = inject('$baseLoading')
  const $baseMessage = inject('$baseMessage')

  const dialogVisible = ref(false)
  const state = reactive({
    form: {
      checkMode: 0,
    },
  })
  const mesReport = ref()
  const checkModes = ref([
    { id: 0, checkModeName: '全检' },
    { id: 1, checkModeName: '抽检' },
  ])

  const openDialog = (value) => {
    dialogVisible.value = true
    mesReport.value = value
  }

  const reportInspect = async () => {
    const load = $baseLoading()
    try {
      let params = {
        inspectQty: mesReport.value.inQty,
        pkProductH: mesReport.value.pkProductH,
        pkCorp: mesReport.value.pkCorp,
        pkInv: mesReport.value.pkInv,
        checkMode: state.form.checkMode,
      }
      const { code, msg } = await productReportInspectApi(params)
      if (code === 2000) {
        $baseMessage(msg, 'success')
        dialogVisible.value = false
        _emit('success-callback')
      } else {
        $baseMessage(res.msg, 'error')
      }
    } finally {
      load.close()
    }
  }

  defineExpose({ openDialog })
  const _emit = defineEmits(['success-callback'])
</script>
